/**
 * 
 */
package com.sttg.csp.common.action;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 */
public abstract class BaseAction extends ActionSupport implements SessionAware,
		ServletRequestAware, ServletResponseAware, ServletContextAware {

	/**
	 * Logger for this class
	 */
	protected final Log logger = LogFactory.getLog(BaseAction.class);
	
	protected Map<String, Object> session;

	protected HttpServletRequest request;

	protected HttpServletResponse response;

	protected ServletContext context;

	protected List rows = new ArrayList();

	protected Integer totalRecord = new Integer(0);

	/**
	 * Defined some of actions for dealing with navigate result.
	 */

	public static final String INDEX = "index";

	public static final String INFO = "info";

	public static final String LIST = "list";

	public static final String TREE = "tree";

	public static final String TREE_NODE = "tree_node";

	public static final String OPE_INFO = "ope_info";

	public static final String ERROR_PAGE = "error_page";
	
	public static final String CHECK_INDEX = "check_index";
	
	public static final String CHECK_INPUT = "check_input";
	
	public static final String CHECK_INFO = "check_info";

	public static final String PRINT = "print";
	
	public static final String NODATA = "nodata";

	public static final String SELECT = "select";
	
	public static final String DOWNLOAD = "download";

	protected int operationType;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.opensymphony.xwork2.ActionSupport#addFieldError(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void addFieldError(String fieldName, String errorMessage) {
		this.addActionError(errorMessage);
		super.addFieldError(fieldName, errorMessage);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.struts2.interceptor.ServletResponseAware#setServletResponse
	 * (javax.servlet.http.HttpServletResponse)
	 */
	public void setServletResponse(HttpServletResponse session) {
		this.response = session;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(
	 * javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	/**
	 * @return the session
	 */
	public Map<String, Object> getSession() {
		return session;
	}

	/**
	 * @return the request
	 */
	public HttpServletRequest getRequest() {
		return request;
	}

	/**
	 * @return the response
	 */
	public HttpServletResponse getResponse() {
		return response;
	}

	/**
	 * @return the rows
	 */
	public abstract List getRows();

	/**
	 * @param rows
	 *            the rows to set
	 */
	public void setRows(List rows) {
		this.rows = rows;
	}

	/**
	 * @return the totalNum
	 */
	public abstract Integer getTotalNum();

	public int getOperationType() {
		return operationType;
	}

	public void setOperationType(int operationType) {
		this.operationType = operationType;
	}

	/**
	 * @param context
	 */
	public void setServletContext(ServletContext context) {
		this.context = context;
	}
}